from flask import Flask,render_template,request
from bokeh.resources import INLINE
import pandas as pd
from bokeh.embed import components
from pyecharts import options as opts
from pyecharts.charts import Geo,Map
from collections import Counter
from pyecharts.charts import Map
from pyecharts.faker import Faker
from pyecharts.globals import ThemeType
from pyecharts.charts import Pie
from pyecharts.charts import Bar, Timeline
from pyecharts.charts import Liquid
from pyecharts.charts import Geo
from pyecharts.globals import ChartType, SymbolType
from pyecharts.charts import TreeMap
from pyecharts.charts import Line
from pyecharts.charts import WordCloud

app = Flask(__name__)
df_高校 = pd.read_excel('全国高校.xlsx')
df_世界高校 = pd.read_excel('世界高校排名.xlsx')




country_col = list(df_世界高校['排名'].dropna().unique())

@app.route('/wp_page',methods=['GET'])
def wp_page():
    data_st = df_世界高校.head(10)
    data_str = data_st.to_html()

    return render_template('table.html',
                           the_res = data_str,

                           the_select_shen=country_col,
                           )

@app.route('/wp_page',methods=['POST'])
def hu_run_select() -> 'html':
    the_region = request.form["the_region_selected"]
    dfs = df_世界高校.query("排名=='{}'".format(the_region))
    data_str = dfs.to_html()
    return render_template('table.html',
                           the_res=data_str,
                           the_select_shen=country_col,
                           # the_select_region=regions_available,
                           )



@app.route('/')
def index():
     return render_template('dashboard.html')



@app.route('/entry')
def entry_page():
    return render_template('dashboard.html')

@app.route('/xingzhi')
def xingzhi_page():
    return render_template('typography.html')
@app.route('/type')
def type_page():
    return render_template('type.html')

@app.route('/map1')
def map1_page():
    return render_template('map.html')
@app.route('/tree')
def tree_page():
    return render_template('tree.html')
@app.route('/loudou')
def loudou_page():
    return render_template('loudou.html')


def bar1():
    df_高校 = pd.read_csv('全国高校.xlsx')
    view_month_number = df_高校[["name", "view_month_number"]].sort_values(by="view_month_number", ascending=False).head(
        12)
    # 图形绘制
    bar1 = (Bar()
            .add_xaxis(view_month_number["name"].tolist())
            .add_yaxis("", view_month_number["view_month_number"].tolist())
            .set_series_opts(label_opts=opts.LabelOpts(is_show=True,
                                                       position='outsideLeft',
                                                       font_style='italic'),
                             itemstyle_opts=opts.ItemStyleOpts(
                                 color='rgb(199, 0, 0, 0.2)'
                             )
            .set_global_opts(
        title_opts=opts.TitleOpts(title="月浏览量top12的学校",
                                  subtitle='',
                                  title_textstyle_opts=opts.TextStyleOpts(), pos_left="center", pos_top="0", ),

    )
            .reversal_axis()

                             )
    .render('bar1月浏览.html'))
    with open("bar1月浏览.html", encoding="utf8", mode="r") as f:
            plot_a = "".join(f.readlines())
    return render_template(
    'index.html',rl=plot_a,a='active',wz=''
    )




if __name__ == '__main__':
    app.run()
